package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.AdminMapper;
import com.situ.mymall.pojo.entity.Admin;
import com.situ.mymall.pojo.query.AdminQuery;
import com.situ.mymall.service.IAdminService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements IAdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public PageResult list(AdminQuery adminQuery) {
        PageHelper.startPage(adminQuery.getPage(), adminQuery.getLimit());
        List<Admin> list = adminMapper.list(adminQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public Admin selectById(Integer id) {
        return adminMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(Admin admin) {
        adminMapper.insertSelective(admin);
    }

    @Override
    public void deleteById(Integer id) {
        adminMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        adminMapper.deleteAll(ids);
    }

    @Override
    public void update(Admin admin) {
        adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public void updateStatus(Integer id, Integer status) {
        adminMapper.updateStatus(id,status);
    }

    @Override
    public Admin login(String name, String password) {
        return adminMapper.login(name,password);
    }

    @Override
    public void updatePass(Integer id, Integer newPassword) {
        adminMapper.updatePass(id,newPassword);
    }

    @Override
    public void updateAdmin(Admin admin) {
        adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public void updatePic(Admin admin) {
        adminMapper.updatePic(admin);
    }
}
